var openid2

Page({
  searchInDb(e){
    console.log("look",e)
    return 0
  },
   submit:async function(e){//与wxml中的 开始配对 按钮绑定
    console.log("事件",e),
    wx.showModal({   
      title:"是否确认开始配对",
      content:"一天只有3次配对机会哦",
      async success(res){
        console.log("用户点击了确认",res)
        if(res.confirm==true){
          var myDate = new Date();
          
          await wx.cloud.callFunction({//上传数据
            name:'pairing',
            data:{
              need_grade: e.detail.value.grade,
              need_sex:e.detail.value.sex,
              need_reserve_today:e.detail.value.reserve_today,
              date: myDate.toLocaleDateString(),     //获取当前日期
            }
          }).then(async res=>{
            console.log('see',res)
            if(res.result.code==200){
              openid2=res.result.openid
            await wx.cloud.database().collection('userAll').where({
              openid:openid2
            })
            .get().then(res=>{
              console.log('see1',res)
              var avatarUrl2=res.data[0].avatarUrl
              var nickName2=res.data[0].nickName
             
              wx.navigateTo({
                url: '../room/room?openid2='+ openid2+'&avatarUrl2='+ avatarUrl2+'&nickName2='+nickName2 
              })
            })
            }else{
              wx.showToast({
                title: '天煞孤星，暂时无人和你配对',
                icon: 'none',
                duration: 2000
              })
            }
            
            
          })

        }
      }
    })
  }
  

})